#include "ReferenceTimeFilter.h"

ReferenceTimeFilter::ReferenceTimeFilter(HRESULT *hr):
CBaseFilter(NAME("Time filter"), NULL, &m_Lock, CLSID_NULL, hr),
m_FixTime(0),
m_PausedTime(0),
m_PauseCount(0),
m_CurrentIndex(0)
{

}

HRESULT ReferenceTimeFilter::GetTime(REFERENCE_TIME *pTime)
{
//	if (m_PauseCount != 0)
//	{
		*pTime = *pTime + m_FixTime;
		return S_OK;
//	}
//	HRESULT hr =  CBaseReferenceClock::GetTime(pTime);
// 	if (hr != S_OK)
// 	{
// 		return hr;
// 	}
// 
// 	*pTime += m_FixTime;
//	return hr;
}

void ReferenceTimeFilter::pauseTime()
{
	if(m_PauseCount++ > 0)
	{
		return ;
	}
	CRefTime tmpTime;
	StreamTime(tmpTime);
	m_PausedTime = tmpTime;
//	CBaseReferenceClock::GetTime(&m_PausedTime);
	return ;
}

void ReferenceTimeFilter::startTime()
{
	if (--m_PauseCount == 0)
	{
		CRefTime currentTime;
		StreamTime(currentTime);
//		CBaseReferenceClock::GetTime(&currentTime);
		m_FixTime += (currentTime - m_PausedTime);
//		CBaseReferenceClock::SetTimeDelta(-m_FixTime);
	}
}

void ReferenceTimeFilter::clearFix()
{
//	CBaseReferenceClock::SetTimeDelta(m_FixTime);
	m_FixTime = 0;
// 	m_PauseCount = 0;
// 	m_PausedTime = 0;
}